﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HBAClient
{
    public partial class Dashboard : Form
    {
        public Dashboard()
        {
            InitializeComponent();
        }

        private void tmrSetCurrTime_Tick(object sender, EventArgs e)
        {
            lblTime.Text = DateTime.Now.ToString();
        }

		private void lblCloseDash_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void Dashboard_Load(object sender, EventArgs e)
		{
			HBADBDataContext db = new HBADBDataContext();

			var query = from balance in db.Balances
						join bank in db.Banks on balance.BankID equals bank.BankID
						where balance.UserID == Program.GetUserID()
						select new { BankName = bank.BankName, CurrentBalance = balance.CurrentBalance };

			dgvDashboard.DataSource = query;

			AviMark.WEBProxySoapClient webEngine = new AviMark.WEBProxySoapClient();
			try
			{
				lblUSDRateValue.Text = webEngine.GetDollarRate();
				lblLocationValue.Text = webEngine.GetLocation();
			}
			catch (Exception ex)
			{
				MessageBox.Show("Cannot connect external web services : " + ex.Message);
			}

			try
			{
				lblTipValue.Text = webEngine.NextRandomTip();
			}
			catch (Exception ex)
			{
				MessageBox.Show("Cannot connect internal web services : " + ex.Message);
			}

		}
    }
}
